package com.twu.biblioteca;
import java.util.Scanner;
import java.util .ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Demon
 * Date: 13-6-27
 * Time: 上午7:03
 * To change this template use File | Settings | File Templates.
 */
public class UserLogin {

    private ArrayList<User> userList=new ArrayList<User>();
    Helper help=new Helper();
    MenuOption menu;

    private String reserve_book_name;
    private String[] reserve_book_list=new String[10]; //everyone only reserve 10 books
    BookList all_book_list=new BookList();//

    UserLogin(){  //finish the initial of userList
        User one=new User();
        one.setUserName("111-1111");
        userList.add(one);
        User two=new User();
        two.setUserName("111-1112");
        userList.add(two);
        User three=new User();
        three.setUserName("111-1113");
        userList.add(three);
        User four=new User();
        four.setUserName("111-1114");
        userList.add(four);
        User five=new User();
        five.setUserName("111-1115");
        userList.add(five);
        User six=new User();
        six.setUserName("111-1116");
        userList.add(six);
        User seven=new User();
        seven.setUserName("111-1117");
        userList.add(seven);
        User eight=new User();
        eight.setUserName("111-1118");
        userList.add(eight);
        User nine=new User();
        nine.setUserName("111-1119");
        userList.add(nine);
        User ten=new User();
        ten.setUserName("111-1120");
        userList.add(ten);
      }

  /* public void SetProfession(String input) {
        profession=input;
    }

    public int GetUserLevel() {
        return level;
    } */

    public void Login(){
        String strUserName;
        String strUserPassword;
        int index=-1;
        boolean mark=false;
        System.out.println("please input your username(xxx-xxxx):");
        help.helpInput();
        strUserName=help.getWhatInput();
        System.out.println("please input your userpassword:");
        help.helpInput();
        strUserPassword=help.getWhatInput();
        for(User temp:userList) {
            mark=temp.checkUserValid(strUserName,strUserPassword);
            if(mark==true){
                index=userList.indexOf(temp);
                System.out.println("Welcome to The Bangalore Public Library!");
                break;
            }
        }
        if(mark==false)
            System.out.println("You input the wrong user message,please talk to a Librarian. Thank you.");
        if(mark==true){
            System.out.println("You can choose the menu option(1-4)!");
            menu=new MenuOption(userList,index);
            menu.Option( );
        }
    }



    public void SetReserveBookName(String input) {
         reserve_book_name=input;
    }

    public int UpdateReserveBookList() {
        if(all_book_list.CheckReserveBookIsLegal(reserve_book_name)&&CheckReserveBookIsNotExist()){
            //reserve_book_list[reserve_book_list.length]=reserve_book_name;
            System.out.println("Thank You! Enjoy the book!");
            return 1;
        }
        else return 0;
    }

    public boolean CheckReserveBookIsNotExist(){
        for(int i=0;i<reserve_book_list.length;i++){
            if(reserve_book_name==reserve_book_list[i]){
                System.out.println("The book exists already!Thank You! Enjoy the book!");
                return false;
            }
        }
        return true;
    }

    public void ReserveBook(){
        System.out.println("Now,you could choose the book you want to reserve.Please input the book you want to reserve:");
        help.helpInput();
       // UserInput();
        //System.out.print(GetUserInput());
        //String str1=GetUserInput();
        SetReserveBookName(help.getWhatInput());
        //System.out.print(reserve_book_name);
        UpdateReserveBookList();
    }
}
